    ### DATAPACK CREATED BY: ...standing on the shoulders of giants...###

...no really...

##################
# INFERNALDEVICE #
##################
MOST OF THE CODE COMES DIRECT FROM THEIR TUTORIAL ON THIS VERY TOPIC!!! https://www.youtube.com/watch?v=nT5_lgv_gX0

Seriously, this pack wouldn't have been possible without their extensive informative support. Their youtube videos and accompanying datapacks have made projects like this possible. Without them, it would still be stuck in one of the many "Ask 4 Help" forums. Please, check out InfernalDevice's work at their youtube channel: https://www.youtube.com/@InfernalDevice I'm more than willing to wager, you'll learn something not just new, but useful to your datapack ambitions!

#############
# GALSERGEY #
#############
The other giant, whose brain has been picked through the years of reddit posts/comments/responses is GalSergy. You can find their irreplaceable information on reddit: https://www.reddit.com/user/GalSergey/

###############################
# Various Communities & Tools #
###############################
In no particular order: https://mcstacker.net/  https://www.reddit.com/r/MinecraftCommands/  https://misode.github.io/  Cloud Wolf MC's discord community:https://discord.gg/VbsGPB3xmz  https://datapack.wiki/  https://minecraft.wiki/  https://www.plotz.co.uk/ (Amaing that site is still goin' strong!)

A *massive*...

 /$$$$$$$$ /$$   /$$  /$$$$$$  /$$   /$$ /$$   /$$       /$$     /$$ /$$$$$$  /$$   /$$
|__  $$__/| $$  | $$ /$$__  $$| $$$ | $$| $$  /$$/      |  $$   /$$//$$__  $$| $$  | $$
   | $$   | $$  | $$| $$  \ $$| $$$$| $$| $$ /$$/        \  $$ /$$/| $$  \ $$| $$  | $$
   | $$   | $$$$$$$$| $$$$$$$$| $$ $$ $$| $$$$$/          \  $$$$/ | $$  | $$| $$  | $$
   | $$   | $$__  $$| $$__  $$| $$  $$$$| $$  $$           \  $$/  | $$  | $$| $$  | $$
   | $$   | $$  | $$| $$  | $$| $$\  $$$| $$\  $$           | $$   | $$  | $$| $$  | $$
   | $$   | $$  | $$| $$  | $$| $$ \  $$| $$ \  $$          | $$   |  $$$$$$/|  $$$$$$/
   |__/   |__/  |__/|__/  |__/|__/  \__/|__/  \__/          |__/    \______/  \______/ 

...to all of those mentioned! (Font made using https://patorjk.com/software/taag/)

#########################################################################################################################

    ##############################
    ## HOW TO USE THIS DATAPACK ##
    ##############################
## Separate multi-enchanted books into individual enchanted books: ##
-Separate multiple enchantments from a single enchanted book by holding the 'MULTI-ENCHANTED BOOK' in the 'OFFHAND', enough 'BOOKS' in the 'MAIN HAND', and then 'RIGHT CLICK' on a 'GRIND STONE'. 
-(If there is only 1 enchantment, or not enough books in the main hand, an error message will indicate such.)

!⯀!NOTE: After the enchantments separate, the grindstone GUI will still be open and the multi-enchanted book will still be in the off hand. Rest assured, this is just a visual artifact. Even 'swapping hands' won't bring that book back into reality!⯀!


    ########################################
    ### SEPARATING MULTI-ENCHANTED BOOKS ###
    ########################################
This system enables any 'Enchanted Book', with multiple enchantments, to have each individual enchantment extracted to it's own book. This only happens when:
- The player has the multi-enchanted book in their off hand.
- The Player has enough empty books in their main hand. (1 fewer than the total enchantments, as the multi-enchanted book, is counted as...a book.)
- With the previous two condition met, the player 'right clicks' on a grind stone. Then the system operates.

    #############################
    # How this is accomplished: #
1.The advancement 'separate_enchantments_advancement' triggers if the player has an enchanted book in their off hand, a book in their main hand, and if they 'right clicked' on a grind stone.

2. 'separate_enchantments_reward' 1st runs to count the number of enchantments present on the enchanted book in the players offhand by running...

3. 'counting_inspect_enchantments' this function takes an enchantment from the list of all enchantments and then runs #4 before removing the selected enchantment from the list, and moving onto the next.

4. 'counting_verify_enchantment_and_level' this function finally takes the selected enchantment from the previous function, and check every level of it, to see if it's present on the enchanted book. If it is, the score for 'CURRENT_ENCHANTMENTS' in "ENCHANTMENT_COUNT" is increased by '1'. Once this function completes, step #3 removes the recently checked-for enchantments, and selected another, repeating #4 until all enchantments and their levels have been counted.

5. Back to 'separate_enchantments_reward', if the count of enchantments is 1, then an error message is displayed indicating such. After that, the number of books present in the players main hand are counted, and if that number is less than the count of enchantments on the enchanted book in the offhand, an error message informs the player. Assuming these checks are passed, then...

6. 'give_inspect_enchantments' this does the same exact as step #3. It just passes an enchantment from the list of all enchantments over to 'give_verify_enchantment_and_level' before removing the current enchantment form the list, and moving onto the next one.

7. 'give_verify_enchantment_and_level' does the same as 'count_verify_enchantment_and_level' but instead of counting enchantments, upon success, this function runs...

8. 'give_enchanted_book' which give the player an enchanted book with the enchantment and level that was passed from the previous functions. This also decreases the score of 'CURRENT_ENCHANTMENTS' for 'ENCHANTMENT_COUNT' by '1', deletes a book, every time this function runs, until that count is '0'. It also plays a sound to better identify the event.

9. Lastly, back to `separate_enchantments_reward' the enchanted book, in the offhand of the player is deleted.